package com.scm.web.controller.purchase;

import java.util.List;

import com.scm.common.core.domain.entity.SysUser;
import com.scm.persist.model.ScmInquiry;
import com.scm.service.IScmInquiryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.scm.common.annotation.Log;
import com.scm.common.enums.BusinessType;
import com.scm.common.core.controller.BaseController;
import com.scm.common.core.domain.AjaxResult;
import com.scm.common.utils.poi.ExcelUtil;
import com.scm.common.core.page.TableDataInfo;

/**
 * 询价单Controller
 *
 * @author reptilemanager
 * @date 2024-06-01
 */
@Controller
@RequestMapping("/scm/inquiry")
public class ScmInquiryController extends BaseController
{
    private String prefix = "inquiry";

    @Autowired
    private IScmInquiryService scmInquiryService;

    @RequiresPermissions("system:inquiry:view")
    @GetMapping()
    public String inquiry()
    {
        return prefix + "/inquiry";
    }

    /**
     * 查询询价单列表
     */
    @RequiresPermissions("system:inquiry:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ScmInquiry scmInquiry)
    {
        startPage();
        SysUser sysUser = getSysUser();
        List<ScmInquiry> list = scmInquiryService.selectScmInquiryList(scmInquiry, sysUser);
        return getDataTable(list);
    }

    /**
     * 导出询价单列表
     */
    @RequiresPermissions("system:inquiry:export")
    @Log(title = "询价单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ScmInquiry scmInquiry)
    {
        SysUser sysUser = getSysUser();
        List<ScmInquiry> list = scmInquiryService.selectScmInquiryList(scmInquiry,sysUser);
        ExcelUtil<ScmInquiry> util = new ExcelUtil<ScmInquiry>(ScmInquiry.class);
        return util.exportExcel(list, "询价单数据");
    }

    /**
     * 新增询价单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存询价单
     */
    @RequiresPermissions("system:inquiry:add")
    @Log(title = "询价单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ScmInquiry scmInquiry)
    {
        SysUser sysUser = getSysUser();
        scmInquiry.setTenantId(sysUser.getTenantId());
        return toAjax(scmInquiryService.insertScmInquiry(scmInquiry));
    }

    /**
     * 修改询价单
     */
    @RequiresPermissions("system:inquiry:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ScmInquiry scmInquiry = scmInquiryService.selectScmInquiryById(id);
        mmap.put("scmInquiry", scmInquiry);
        return prefix + "/edit";
    }

    /**
     * 修改保存询价单
     */
    @RequiresPermissions("system:inquiry:edit")
    @Log(title = "询价单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ScmInquiry scmInquiry)
    {
        scmInquiry.setTenantId(getSysUser().getTenantId());
        return toAjax(scmInquiryService.updateScmInquiry(scmInquiry));
    }

    /**
     * 删除询价单
     */
    @RequiresPermissions("system:inquiry:remove")
    @Log(title = "询价单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(scmInquiryService.deleteScmInquiryByIds(ids));
    }
}
